$(document).ready(function() {

    /* Every time the window is scrolled ... */
    $(window).scroll( function(){

        /* Check the location of each desired element */
        $('.card-fade-in').each( function(i){

            // var bottom_of_object = $(this).position().top + $(this).outerHeight();
            var top_1p5_of_object = $(this).position().top + 1/5 * $(this).outerHeight();
            var bottom_of_window = $(window).scrollTop() + $(window).height();

            /* If the object is completely visible in the window, fade it it */
            if( bottom_of_window > top_1p5_of_object ){
                $(this).animate({'opacity':'1'},1000);
            }

        });

    });

    $(window).scroll( function(){

        /* Check the location of each desired element */
        $('.from-left').each( function(i){

            // var bottom_of_object = $(this).position().top + $(this).outerHeight();
            var top_1p5_of_object = $(this).position().top + 1/5 * $(this).outerHeight();
            var bottom_of_window = $(window).scrollTop() + $(window).height();

            /* If the object is completely visible in the window, fade it it */
            if( bottom_of_window > top_1p5_of_object ){
                $(this).removeClass('from-left')
            }

        });

    });

    $(window).scroll( function(){

        /* Check the location of each desired element */
        $('.from-right').each( function(i){

            // var bottom_of_object = $(this).position().top + $(this).outerHeight();
            var top_1p5_of_object = $(this).position().top + 1/5 * $(this).outerHeight();
            var bottom_of_window = $(window).scrollTop() + $(window).height();

            /* If the object is completely visible in the window, fade it it */
            if( bottom_of_window > top_1p5_of_object ){
                $(this).removeClass('from-right')
            }

        });

    });

});